import axios from 'axios';

export interface MenuQueryVO {
  id: string; // 菜单id
  name: string; // 菜单名称
}
export interface PortalVo {
  id: string;
  enableFlag: string;
  icon: string;
  name: string;
  sortNumber: number;
  sysInnerFlag: string;
  terminal: string;
  type: string;
  url: string;
  menuQueryVOList: MenuQueryVO[];
}

export interface PortalListParams {
  terminal: string;
}

export function selectAllPortal(params: PortalListParams) {
  return axios.get<PortalVo[]>('tenant/portal/selectAllPortal', { params });
}

export function createPortal(params: PortalVo) {
  return axios.post<string>('tenant/portal/createPortal', params);
}

export function editPortal(params: PortalVo) {
  return axios.post<string>('tenant/portal/editPortal', params);
}

export function deletePortal(id: string) {
  return axios.get<string>(`tenant/portal/deletePortal?id=${id}`);
}

export interface MenuVo {
  id: string;
  icon: string;
  name: string;
  openFlag: string;
  parentId: string;
  portalId: string;
  sortNumber?: number;
  sysAdminFlag: string;
  requiresAuth: string;
  type: string;
  url: string;
}
export interface Menu {
  checkedFlag: string;
  id: string;
  name: string;
  parentId: string;
  portalId: string;
}
export interface MenuTreeVo {
  id: string;
  name: string;
  menus: Menu[];
}

export interface MenuListParams {
  portalId: string;
}

export function selectMenuTree() {
  return axios.post<MenuTreeVo[]>('tenant/menu/getMenuTree');
}
export function selectAllMenu(portalId: string) {
  return axios.post<MenuVo[]>(`tenant/menu/findPageMenus/${portalId}`);
}

export function createMenu(params: MenuVo) {
  return axios.post<string>('tenant/menu/create', params);
}

export function editMenu(params: MenuVo) {
  return axios.post<string>('tenant/menu/edit', params);
}

export function deleteMenu(id: string) {
  return axios.post<string>(`tenant/menu/delete/${id}`);
}
